package com.soft.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//action.jsp    调用验证码,先判断验证码是否正确,正确后判断账号密码,并给出相应的提示
//这个判断Servlet没有用,也可以在这个里面写
@WebServlet("/AuthcodeJudge")
public class AuthcodeJudgeServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取前端输入的验证码值
        String yanzhengma = request.getParameter("authcode");
        //后端生成的验证码的值
        String yanzhengma1 = (String)request.getSession().getAttribute("yanzhengma");
        if(yanzhengma1.equals(yanzhengma)){
            System.out.println("验证码正确！！");
        //request.getRequestDispatcher("/sys/action.jsp").forward(request,response);
            response.sendRedirect("/red_wine/sys/action.jsp");
        }else{
            System.out.println("验证码错误！！！");
            request.getSession().setAttribute("yancuo","验证码错误");
            response.sendRedirect("/red_wine/sys/login.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

}
